<template lang="pug">
    Modal.lzw-modal-style-1(v-model="dispatchShow" fullscreen title="定向派单")
      .user-list(v-if="dispatchShow")
        Table.hasTitle-table.beautiful-table(width="100%" stripe :columns="thead" :data="listData" :loading="loading" @on-selection-change="tableSelectChange")
          .pl-20.pt-6(slot="header")
            Input.lzw-input(v-model="idCardNo" search clearable enter-button placeholder="请输入员工姓名" style="width:400px" @on-search="search")
          template(slot-scope="{ row, index }" slot="orderCount")
            span {{row.orderCount.completeOrder}}
          template(slot-scope="{ row, index }" slot="d")
            Rate(show-text allow-half disabled v-model="row.d")
              span(style="color:#f5a623") {{row.d}}
          .clearfix.pl-20.pr-20(slot="footer")
            Page(:total="totalcount" :current="pageIndex" :page-size="pageSize" @on-change="pageChange" show-total)
      .text-center(slot="footer")
        //- Button(@click="dispatchShow=false") 全选
        Button(@click="dispatchShow=false") 取消
        Button(type="info" @click="confirmFn") 确定派单
</template>

<script>
import vOrderApi from '@/api/v_order.api.js'

export default {
  props: {
    orderId: String
  },
  data () {
    return {
      ids: [], // 指派员工id
      loading: false,
      dispatchShow: false,
      idCardNo: '',
      thead: [
        {
          type: 'selection',
          width: 60,
          fixed: 'left'
        },
        {
          title: '姓名',
          key: 'name',
          minWidth: 150
        },
        {
          title: '身份证号',
          key: 'idCardNo',
          minWidth: 150
        },
        {
          title: '居住地',
          key: 'residentAddress',
          minWidth: 150
        },
        {
          title: '完成订单',
          slot: 'orderCount',
          minWidth: 150
        },
        {
          title: '用户评价',
          key: 'd',
          slot: 'd',
          minWidth: 150
        }
      ],
      listData: [],
      totalcount: 0,
      pageIndex: 1,
      pageSize: 10
    }
  },
  created () {
    this.getAllWorker()
  },
  methods: {
    search () {
      this.getAllWorker()
    },
    modalOpen () {
      this.dispatchShow = true
    },
    confirmFn () {
      if (this.ids.length > 0) {
        vOrderApi.dispatchVOrder({
          DetaiIds: this.ids,
          OrderId: this.orderId,
          Userid: JSON.parse(localStorage.getItem('clientLoginInfo')).data.userId
        }).then(res => {
          console.log(res)
          if (res.data.success) {
            this.$Message.success(res.data.message)
            this.dispatchShow = false
            this.$emit('get-list')
            this.ids = []
          } else {
            
            this.$Message.error({
              content: res.data.message,
              duration: 10,
              closable: true
            })
          }
        })
      } else {
        this.$Message.warning('请选择你要指派的员工')
      }
    },
    tableSelectChange (val) {
      console.log(val)
      this.ids = val.map(item => {
        return item.id
      })
    },
    pageChange (index) {
      this.pageIndex = index
      this.getAllWorker()
    },
    getAllWorker () {
      vOrderApi.getAllWorker({
        IdCardNo: this.idCardNo,
        DataSource: 1,
        AuditStatus: 1,
        PageIndex: this.pageIndex,
        PageSize: this.pageSize
      }).then(res => {
        if (res.data.success) {
          this.listData = res.data.data
          this.totalcount = res.data.totalRows
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    }
  }
}
</script>

<style lang="less">
  .lzw-input{
    .ivu-input-icon{
      right: 50px;
    }
  }
</style>
